package org.rockyang.dike.utils;


import org.rockyang.dike.core.AuthorizationInfo;
import org.rockyang.dike.core.SubjectManager;

/**
 * @author yangjian
 */
public class AuthorizationUtils {

	/**
	 * 获取授权认证管理对象
	 * @return
	 */
	public static SubjectManager getAuthorizationManager() {
		return ThreadContext.getAuthorizationManager();
	}

	/**
	 * 获取当前登录对象
	 * @return
	 */
	public static Object getCurrentLoginSubject() {
		try {
			return getAuthorizationManager().getPrimaryAuthenticationInfo().getUserInfo();
		} catch (NullPointerException e) {
			return null;
		}
	}

	/**
	 * 获取当前登录用户的授权信息
	 * @return
	 */
	public static AuthorizationInfo getCurrentAuthorizationInfo() {
		return getAuthorizationManager().getAuthorizationInfo();
	}

	/**
	 * 绑定授权认证对象
	 * @param subjectManager
	 */
	public static void bindAuthorizationManager(SubjectManager subjectManager) {
		ThreadContext.bindAuthorizationManager(subjectManager);
	}

}
